package xzy.Controller;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import xzy.dao.StudentMesMapper;
import xzy.pojo.StudentMes;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ExcelServlet")
public class Excel_Servlet extends HttpServlet {
    private static ApplicationContext context=new ClassPathXmlApplicationContext("application.xml");
    StudentMesMapper studentMesMapper= (StudentMesMapper) context.getBean("studentMesMapper");
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            studentMesMapper.excel();
            request.setAttribute("Resgist_error","导出成功[H://studentMes.xls]");
        }catch (Exception e){
            request.setAttribute("Resgist_error","表已存在，请删除后重导出");
        }
        request.getRequestDispatcher("/Regist.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
